import Axios from '@/util/ajax'

const state = {
    deptTreeData:[],
    effortTypes:[],
    effortWeights:[],
    allDepts:[],
    defaultProps: {
        children: 'child',
        label: 'name'
    },
};

const mutations = {
    Set_Dept_Tree_Data: (state, data) => {
        state.deptTreeData = data
    },

    Set_Dropdown_Values: (state, res) => {
        state.effortTypes = res.effortTypes;
        state.effortWeights = res.effortWeights;
        state.allDepts = res.allDepts;
    },

};

const actions = {
    async fetchDeptTreeData({commit}){
        console.log("fetchDeptTreeData");
        let res = await Axios.get("/hr/dept/all", {});
        commit('Set_Dept_Tree_Data',  res.result);
    },

    async fetchDropdownValues({commit}){
        console.log("fetchDropdownValues");
        let res = await Axios.get("/hr/dept/dropdown", {});
        commit('Set_Dropdown_Values',  res.result);
    },
};

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
